//

import UIKit
//处理微博模型显示的内容
class CZStatusViewModel: NSObject {
    
    //转发数显示
    var retweetStr: String?
    //评论数显示
    var commentStr: String?
    //赞数显示
    var goodStr: String?
    //拼接转发内容""
    var retweetContent: String?
    
    //持有微博模型
    var status: CZStatus?
    init(status: CZStatus) {
        super.init()
        //初始化
        self.status = status

        retweetStr = handleCount(status.reposts_count, defaTitle: "转发")
        commentStr = handleCount(status.comments_count, defaTitle: "评论")
        goodStr = handleCount(status.attitudes_count, defaTitle: "赞")
        //转发微博内容显示
        hanleRetweetContent(status)
        
    }
    
    //处理微博内容显示
    private func hanleRetweetContent(status: CZStatus) {
        
        if status.retweeted_status != nil {
            
            //获得转发用户名称
            guard let name = status.retweeted_status?.user?.screen_name, let text = status.retweeted_status?.text else {
                return
            }
            //到这 就能获得name和转发的微博
            
            retweetContent = "@\(name): \(text)"
            
            
            }
            
 
        }
        
    }
    
    
    //处理显示评论
    private func handleCount(count: Int,defaTitle: String) -> String {
        
        if count > 0 {
        if count >= 10000 {
                //进行处理
                let result = Float(count / 1000) / 10
                
                var resultStr = "\(result)万"
            
            //查找这个字符串是否含有.0
            if resultStr.containsString(".0") {
                //换值
                resultStr = resultStr.stringByReplacingOccurrencesOfString(".0", withString: "")
            }
                
            return resultStr
                
            }
            return "\(count)"
            
            
        } else {
            return defaTitle
        }
    }

















